package com.blog.security.controller;

import com.blog.common.RespBean;
import com.blog.security.entity.AuthUserDetails;
import com.blog.security.service.BaseMenuService;
import com.blog.security.entity.Menu;
import com.blog.system.Hr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @ClassName securityMenu
 * @Destription 后端控制登录后可操作的菜单
 * @Author 天堂小野花
 * @Date 2025/8/8  18:27
 * @Version 1.0
 */
@RestController
public class securityMenu {
    @Autowired
    BaseMenuService baseMenuService;
    @GetMapping("/plateform/security/menu")
    public List<Menu> getMenuByHrId(Authentication authentication){

        LinkedHashMap<String, Object> principal = (LinkedHashMap<String, Object>)authentication.getPrincipal();

        //不使用前端传过来的数据，有风险的
        return baseMenuService.getMenuByHrId((Integer) principal.get("id"));
    }
    @PostMapping("/plateform/security/addHr")
    public RespBean addUsers(@RequestBody Hr form){
        if(baseMenuService.addUsers(form)==1){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
}
